package com.sinopec.uhf.chengwei.net

import com.rscja.deviceapi.enums.AntennaEnum
import com.rscja.deviceapi.interfaces.IUHFA4
import com.sinopec.iuhf.IUHFSettings
import kotlinx.coroutines.delay

/**
 *
 * 好像有点问题 这里的功率是指第一个天线功率
 *
 */
class Power(private val rfid: IUHFA4) : IUHFSettings.ASeting<Int> {
    override suspend fun get(): Int {
        delay(3000)
        val powers = rfid.antennaPower
        return powers?.getOrNull(0)?.power ?: 0

    }

    private val ants = listOf(
        AntennaEnum.ANT1,
        AntennaEnum.ANT2,
        AntennaEnum.ANT3,
        AntennaEnum.ANT4,
        AntennaEnum.ANT5,
        AntennaEnum.ANT6,
        AntennaEnum.ANT7,
        AntennaEnum.ANT8,
    )

    override suspend fun set(t: Int): Result<*> {
        ants.forEach {
            rfid.setAntennaPower(it, t)
            delay(50)
        }
        return Result.success(Unit)

    }
}